using System;
using System.Data;
using System.Collections;
using System.Runtime.Serialization;
using Widgetsphere.Core.Util;
using Widgetsphere.Core.DataAccess;
using System.Collections.Generic;
using ACME.Northwind.Business.Objects;
using ACME.Northwind.Domain.Objects;

namespace ACME.Northwind.Business.SelectCommands
{
	#region OrderSelectAll

	/// <summary>
	/// The select command used to select all rows from the 'Order' table
	/// </summary>
	[Serializable]
	public partial class OrderSelectAll : SelectCommand, ISerializable
	{

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected OrderSelectAll(SerializationInfo info, StreamingContext context): base(info,context)
		{
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
		}

		#endregion 

		/// <summary>
		/// Default constructor
		/// </summary>
		public OrderSelectAll()
		{
		}

		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainOrderCollection colDomain = new DomainOrderCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values to populate a 'Order' collection
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "gen_OrderSelect"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region OrderPagedSelect

	/// <summary>
	/// Select command used to perform paged selects from the 'Order' table
	/// </summary>
	[Serializable]
	public partial class OrderPagedSelect : SelectCommand, ISerializable
	{
		private int mPage; 
		private int mPageSize;
		private string mOrderByColumn;
		private bool mAscending;
		private string mFilter;
		private int mCount = -1;

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected OrderPagedSelect(SerializationInfo info, StreamingContext context): base(info,context)
		{
			mPage = info.GetInt32("mPage");
			mPageSize = info.GetInt32("mPageSize");
			mOrderByColumn = info.GetString("mOrderByColumn");
			mAscending = info.GetBoolean("mAscending");
			mFilter = info.GetString("mFilter");
			mCount = info.GetInt32("mCount");
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			info.AddValue("mPage", mPage);
			info.AddValue("mPageSize", mPageSize);
			info.AddValue("mOrderByColumn", mOrderByColumn);
			info.AddValue("mAscending", mAscending);
			info.AddValue("mFilter", mFilter);
			info.AddValue("mCount", mCount);
		}

		#endregion 

		/// <summary>
		/// Paging select command that allows for the selective page-based selection of database rows
		/// </summary>
		public OrderPagedSelect(int page, int pageSize, string orderByColumn, bool ascending, string filter)
		{
			mPage = page; 
			mPageSize = pageSize;
			mOrderByColumn = orderByColumn;
			mAscending = ascending;
			mFilter = filter;
		}

		/// <summary>
		/// The total number of rows returned. This is populated after the database is queried.
		/// </summary>
		public int Count
		{
		  get { return mCount; }
		}

		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainOrderCollection colDomain = new DomainOrderCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values to populate a 'Order' collection in a paged fashion
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "gen_OrderPagingSelect"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
		}

		/// <summary>
		/// Execute this select command on the database
		/// </summary>
		public override IDomainCollection Execute(SubDomainBase subDomain)
		{
			this.SetupParameterValues(subDomain);
			PersistableDomainCollectionBase returnTable = (PersistableDomainCollectionBase)this.CreateDomainCollection();

			IDbCommand fillCommand = PersistableDomainCollectionBase.GetFillCommand(this.ConnectionString, this.StoredProcedureName);
			fillCommand.CommandTimeout = this.DefaultTimeOut;
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@page", mPage);
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@pageSize", mPageSize);
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@orderByColumn", mOrderByColumn);
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@ascending", mAscending);
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@filter", mFilter);
			IDbDataParameter paramCount = PersistableDomainCollectionBase.GetOutputParameter(fillCommand, "@count");
			returnTable.FillDataTable(this.ConnectionString, fillCommand);
			if(paramCount.Value != System.DBNull.Value)
			{
				mCount = (int)paramCount.Value;
			}
			else
			{
				mCount = 0;
			}
			return returnTable;
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region OrderSelectByPks

	/// <summary>
	/// A select command that selects objects by primary key
	/// </summary>
	[Serializable]
	public partial class OrderSelectByPks : SelectCommand, ISerializable
	{
		private List<OrderPrimaryKey> mPrimaryKeys = null;

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected OrderSelectByPks(SerializationInfo info, StreamingContext context): base(info,context)
		{
			mPrimaryKeys = new List<OrderPrimaryKey>();
			mPrimaryKeys.AddRange((OrderPrimaryKey[])info.GetValue("mPrimaryKeys", typeof(OrderPrimaryKey[])));
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			info.AddValue("mPrimaryKeys", mPrimaryKeys.ToArray());
		}

		#endregion 

		/// <summary>
		/// Select objects by primary key
		/// </summary>
		public OrderSelectByPks(int orderid)
		{
			mPrimaryKeys = new List<OrderPrimaryKey>();
			mPrimaryKeys.Add(new OrderPrimaryKey(orderid));

		}

		/// <summary>
		/// Select objects by a primary key
		/// </summary>
		public OrderSelectByPks(OrderPrimaryKey primaryKey)
		{
			mPrimaryKeys = new List<OrderPrimaryKey>();
			mPrimaryKeys.Add(primaryKey);
		}

		/// <summary>
		/// Select objects by a list of primary keys
		/// </summary>
		public OrderSelectByPks(IEnumerable<OrderPrimaryKey> primaryKeys)
		{
			mPrimaryKeys = new List<OrderPrimaryKey>();
			mPrimaryKeys.AddRange(primaryKeys);
		}

		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainOrderCollection colDomain = new DomainOrderCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values by primary key to populate a 'Order' collection
		/// </summary>
		public override string StoredProcedureName
		{
			get
			{
				if (mPrimaryKeys.Count == 1) return "gen_OrderSelectByOrderSinglePk";
				else return "gen_OrderSelectByOrderPks";
			}
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			if (mPrimaryKeys.Count == 1)
			{
				OrderPrimaryKey key = ((OrderPrimaryKey)mPrimaryKeys[0]);
				ParameterValues.Add("@OrderID", key.OrderId);
			}
			else
				ParameterValues.Add("@xml", DomainOrderCollection.GetPrimaryKeyXml(mPrimaryKeys));
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region OrderSelectByCustomerPks

	/// <summary>
	/// Select command used to select all rows from the 'Order' table based on primary keys
	/// </summary>
	[Serializable]
	public partial class OrderSelectByCustomerPks : SelectCommand, ISerializable
	{
		private string mCustomerPrimaryKeysXml = null;

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected OrderSelectByCustomerPks(SerializationInfo info, StreamingContext context): base(info,context)
		{
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
		}

		#endregion 

		/// <summary>
		/// Default constructor
		/// </summary>
		public OrderSelectByCustomerPks()
		{
		}

		/// <summary>
		/// Constructor that takes a list of primary keys to select
		/// </summary>
		public OrderSelectByCustomerPks(IEnumerable<CustomerPrimaryKey> inCustomerPrimaryKeys)
		{
			mCustomerPrimaryKeysXml = DomainCustomerCollection.GetPrimaryKeyXml(inCustomerPrimaryKeys);
		}

		/// <summary>
		/// Creates a PersistableDomainCollectionBase of a collection type that holds objects selected by this select command
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainOrderCollection colDomain = new DomainOrderCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values by a foreign key to populate a 'Order' collection
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "gen_OrderSelectByCustomerPks"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			SubDomain sd = (SubDomain)subDomain;
			if(mCustomerPrimaryKeysXml != null)
			{
				if (!ParameterValues.ContainsKey("@xml"))
					ParameterValues.Add("@xml", mCustomerPrimaryKeysXml);
			}
			else
			{
				DomainCustomerCollection ic = (DomainCustomerCollection)sd.GetDomainCollection(Collections.CustomerCollection);
				ic.OrderFilled = true;
				if (!ParameterValues.ContainsKey("@xml"))
					ParameterValues.Add("@xml", ic.GetPrimaryKeyXml());
			}
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region OrderSelectByEmployeePks

	/// <summary>
	/// Select command used to select all rows from the 'Order' table based on primary keys
	/// </summary>
	[Serializable]
	public partial class OrderSelectByEmployeePks : SelectCommand, ISerializable
	{
		private string mEmployeePrimaryKeysXml = null;

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected OrderSelectByEmployeePks(SerializationInfo info, StreamingContext context): base(info,context)
		{
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
		}

		#endregion 

		/// <summary>
		/// Default constructor
		/// </summary>
		public OrderSelectByEmployeePks()
		{
		}

		/// <summary>
		/// Constructor that takes a list of primary keys to select
		/// </summary>
		public OrderSelectByEmployeePks(IEnumerable<EmployeePrimaryKey> inEmployeePrimaryKeys)
		{
			mEmployeePrimaryKeysXml = DomainEmployeeCollection.GetPrimaryKeyXml(inEmployeePrimaryKeys);
		}

		/// <summary>
		/// Creates a PersistableDomainCollectionBase of a collection type that holds objects selected by this select command
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainOrderCollection colDomain = new DomainOrderCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values by a foreign key to populate a 'Order' collection
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "gen_OrderSelectByEmployeePks"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			SubDomain sd = (SubDomain)subDomain;
			if(mEmployeePrimaryKeysXml != null)
			{
				if (!ParameterValues.ContainsKey("@xml"))
					ParameterValues.Add("@xml", mEmployeePrimaryKeysXml);
			}
			else
			{
				DomainEmployeeCollection ic = (DomainEmployeeCollection)sd.GetDomainCollection(Collections.EmployeeCollection);
				ic.OrderFilled = true;
				if (!ParameterValues.ContainsKey("@xml"))
					ParameterValues.Add("@xml", ic.GetPrimaryKeyXml());
			}
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region OrderSelectByShipperPks

	/// <summary>
	/// Select command used to select all rows from the 'Order' table based on primary keys
	/// </summary>
	[Serializable]
	public partial class OrderSelectByShipperPks : SelectCommand, ISerializable
	{
		private string mShipperPrimaryKeysXml = null;

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected OrderSelectByShipperPks(SerializationInfo info, StreamingContext context): base(info,context)
		{
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
		}

		#endregion 

		/// <summary>
		/// Default constructor
		/// </summary>
		public OrderSelectByShipperPks()
		{
		}

		/// <summary>
		/// Constructor that takes a list of primary keys to select
		/// </summary>
		public OrderSelectByShipperPks(IEnumerable<ShipperPrimaryKey> inShipperPrimaryKeys)
		{
			mShipperPrimaryKeysXml = DomainShipperCollection.GetPrimaryKeyXml(inShipperPrimaryKeys);
		}

		/// <summary>
		/// Creates a PersistableDomainCollectionBase of a collection type that holds objects selected by this select command
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainOrderCollection colDomain = new DomainOrderCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values by a foreign key to populate a 'Order' collection
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "gen_OrderSelectByShipperPks"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			SubDomain sd = (SubDomain)subDomain;
			if(mShipperPrimaryKeysXml != null)
			{
				if (!ParameterValues.ContainsKey("@xml"))
					ParameterValues.Add("@xml", mShipperPrimaryKeysXml);
			}
			else
			{
				DomainShipperCollection ic = (DomainShipperCollection)sd.GetDomainCollection(Collections.ShipperCollection);
				ic.OrderFilled = true;
				if (!ParameterValues.ContainsKey("@xml"))
					ParameterValues.Add("@xml", ic.GetPrimaryKeyXml());
			}
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region OrderSelectByCreatedDateRange

	/// <summary>
	/// Select objects by their created date.
	/// </summary>
	[Serializable]
	public partial class OrderSelectByCreatedDateRange : SelectCommand, ISerializable
	{
		private DateTime? mStartDate;
		private DateTime? mEndDate;

		#region Serialization

		/// <summary>
		/// Select objects by their created date.
		/// </summary>
		protected OrderSelectByCreatedDateRange(SerializationInfo info, StreamingContext context): base(info,context)
		{
			mStartDate = info.GetDateTime("mStartDate");
			mEndDate = info.GetDateTime("mEndDate");
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			info.AddValue("mStartDate", mStartDate);
			info.AddValue("mEndDate", mEndDate);
		}

		#endregion 

		/// <summary>
		/// Select objects by their created date.
		/// </summary>
		public OrderSelectByCreatedDateRange(DateTime? startDate, DateTime? endDate)
		{
			mStartDate = startDate;
			mEndDate = endDate;
		}

		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainOrderCollection colDomain = new DomainOrderCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values to populate a 'Order' collection in a paged fashion
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "gen_OrderSelectByCreatedDateRange"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			ParameterValues.Add("@start_date", mStartDate);
			ParameterValues.Add("@end_date", mEndDate);
		}

		/// <summary>
		/// Execute this select command on the database
		/// </summary>
		public override IDomainCollection Execute(SubDomainBase subDomain)
		{
			this.SetupParameterValues(subDomain);
			PersistableDomainCollectionBase returnTable = (PersistableDomainCollectionBase)this.CreateDomainCollection();

			IDbCommand fillCommand = PersistableDomainCollectionBase.GetFillCommand(this.ConnectionString, this.StoredProcedureName);
			fillCommand.CommandTimeout = this.DefaultTimeOut;
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@start_date", mStartDate);
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@end_date", mEndDate);
			returnTable.FillDataTable(this.ConnectionString, fillCommand);
			return returnTable;
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region OrderSelectByModifiedDateRange

	/// <summary>
	/// Select objects by their modified date.
	/// </summary>
	[Serializable]
	public partial class OrderSelectByModifiedDateRange : SelectCommand, ISerializable
	{
		private DateTime? mStartDate;
		private DateTime? mEndDate;

		#region Serialization

		/// <summary>
		/// Select objects by their modified date.
		/// </summary>
		protected OrderSelectByModifiedDateRange(SerializationInfo info, StreamingContext context): base(info,context)
		{
			mStartDate = info.GetDateTime("mStartDate");
			mEndDate = info.GetDateTime("mEndDate");
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			info.AddValue("mStartDate", mStartDate);
			info.AddValue("mEndDate", mEndDate);
		}

		#endregion 

		/// <summary>
		/// Select objects by their modified date.
		/// </summary>
		public OrderSelectByModifiedDateRange(DateTime? startDate, DateTime? endDate)
		{
			mStartDate = startDate;
			mEndDate = endDate;
		}

		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainOrderCollection colDomain = new DomainOrderCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values to populate a 'Order' collection in a paged fashion
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "gen_OrderSelectByModifiedDateRange"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			ParameterValues.Add("@start_date", mStartDate);
			ParameterValues.Add("@end_date", mEndDate);
		}

		/// <summary>
		/// Execute this select command on the database
		/// </summary>
		public override IDomainCollection Execute(SubDomainBase subDomain)
		{
			this.SetupParameterValues(subDomain);
			PersistableDomainCollectionBase returnTable = (PersistableDomainCollectionBase)this.CreateDomainCollection();

			IDbCommand fillCommand = PersistableDomainCollectionBase.GetFillCommand(this.ConnectionString, this.StoredProcedureName);
			fillCommand.CommandTimeout = this.DefaultTimeOut;
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@start_date", mStartDate);
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@end_date", mEndDate);
			returnTable.FillDataTable(this.ConnectionString, fillCommand);
			return returnTable;
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region OrderSelectBySearch
	/// <summary>
	/// The select command used to select all rows from the 'Order' table
	/// </summary>
	[Serializable]
	public partial class OrderSelectBySearch : SelectCommand, ISerializable
	{
		private OrderSearch Order;
		private OrderPaging _paging = null;
		private int mCount = -1;

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected OrderSelectBySearch(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
			Order = (OrderSearch)info.GetValue("Order", typeof(OrderSearch));
			_paging = (OrderPaging)info.GetValue("paging", typeof(OrderPaging));
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			info.AddValue("Order", Order);
			info.AddValue("paging", _paging);
		}

		#endregion 

		/// <summary>
		/// The total number of rows returned. This is populated after the database is queried.
		/// </summary>
		public int Count
		{
		  get { return mCount; }
		}

		/// <summary>
		/// Select of objects by the Order search object
		/// </summary>
		public OrderSelectBySearch(OrderSearch searchObject)
		{
			Order = searchObject;
		}

		/// <summary>
		/// Paged select of objects by the Order search object
		/// </summary>
		public OrderSelectBySearch(OrderSearch searchObject, OrderPaging paging)
		{
			Order = searchObject;
			_paging = paging;
		}


		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainOrderCollection colDomain = new DomainOrderCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values by primary key to populate a 'Order' collection
		/// </summary>
		public override string StoredProcedureName
		{
			get
			{
				if (Order.SearchType == SearchType.OR)
					return "gen_OrderSelectBySearchOr";
				else
					return "gen_OrderSelectBySearchAnd";
			}
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			if (_paging != null)
			{
				if (_paging.OrderByList.Count != 1)
					throw new Exception("The select operation supports exactly one OrderBy field.");

				ParameterValues.Add("@paging_Ascending", _paging.OrderByList[0].Ascending);
				ParameterValues.Add("@paging_OrderByColumn", OrderCollection.GetDatabaseFieldName(_paging.OrderByList[0].Field));
				ParameterValues.Add("@paging_PageIndex", _paging.PageIndex);
				ParameterValues.Add("@paging_RecordsperPage", _paging.RecordsperPage);
			}

			if (Order != null)
			{
				if (Order.CustomerId != null)
				{
					ParameterValues.Add("@CustomerID", Order.CustomerId);
				}
				if (Order.EmployeeId != null)
				{
					ParameterValues.Add("@EmployeeID", Order.EmployeeId);
				}
				if (Order.OrderDate != null)
				{
					ParameterValues.Add("@OrderDate", Order.OrderDate);
				}
				if (Order.OrderId != null)
				{
					ParameterValues.Add("@OrderID", Order.OrderId);
				}
				if (Order.RequiredDate != null)
				{
					ParameterValues.Add("@RequiredDate", Order.RequiredDate);
				}
				if (Order.ShipAddress != null)
				{
					ParameterValues.Add("@ShipAddress", Order.ShipAddress);
				}
				if (Order.ShipCity != null)
				{
					ParameterValues.Add("@ShipCity", Order.ShipCity);
				}
				if (Order.ShipCountry != null)
				{
					ParameterValues.Add("@ShipCountry", Order.ShipCountry);
				}
				if (Order.ShipName != null)
				{
					ParameterValues.Add("@ShipName", Order.ShipName);
				}
				if (Order.ShippedDate != null)
				{
					ParameterValues.Add("@ShippedDate", Order.ShippedDate);
				}
				if (Order.ShipPostalCode != null)
				{
					ParameterValues.Add("@ShipPostalCode", Order.ShipPostalCode);
				}
				if (Order.ShipRegion != null)
				{
					ParameterValues.Add("@ShipRegion", Order.ShipRegion);
				}
				if (Order.ShipVia != null)
				{
					ParameterValues.Add("@ShipVia", Order.ShipVia);
				}

			}
		}

		/// <summary>
		/// Execute this select command on the database
		/// </summary>
		public override IDomainCollection Execute(SubDomainBase subDomain)
		{
			this.SetupParameterValues(subDomain);
			PersistableDomainCollectionBase returnTable = (PersistableDomainCollectionBase)this.CreateDomainCollection();

			IDbCommand fillCommand = PersistableDomainCollectionBase.GetFillCommand(this.ConnectionString, this.StoredProcedureName);
			fillCommand.CommandTimeout = this.DefaultTimeOut;

			//Add the parameters
			foreach (string key in ParameterValues.Keys)
			{
				PersistableDomainCollectionBase.SetParameterValue(fillCommand, key, ParameterValues[key]);
			}

			IDbDataParameter paramCount = null;
			paramCount = PersistableDomainCollectionBase.GetOutputParameter(fillCommand, "@paging_Count");

			returnTable.FillDataTable(this.ConnectionString, fillCommand);

			if (_paging != null)
			{
				if (paramCount.Value != System.DBNull.Value) mCount = (int)paramCount.Value;
				else mCount = 0;
			}

			return returnTable;
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion


	}

	#endregion
}
